// const { json } = require("express");

new Vue({
	el: '#app',
	data: function () {
		return {
			// 日历
			currentDay: 1, // 当前天
			currentMonth: 1, // 当前月
			currentYear: 1970,
			currentWeek: 0, // 一号所在的星期
			days: [], // 当月所有天数
			content: {},
			sign_days: [], // 签到日期
			is_sign: false,
			currentPlan: {},
			selectItem: '2021',
            items: [
                {id:'2021', name: '2021年05月15日'},
            ],
			selectMonth:'1',
			monthOptions:[],
			selectTypeId:'',
			selectTypeValue:'',
			allRepairTypeOptions:[
				{value:'',text:'请选择维修类型'},
			],
			allRepairPeople:[
				{id:'',value:'请选择值班维修人员'},
			],
			repairPeopleStaffId:'',
			repairPeopleStaffValue:'',

			querySelectTypeId:'',
			querySelectTypeValue:'',
			beginWorkTime:'',
			bottomId:null,
			personList:'',
			isShow:-1,
			chooseNum:0,
			showSchedul:false, //显示排班弹框-用作动画
			showSchedulAll:false, //显示排班弹框

			showTime:false, //显示时间弹框-用作动画
			showTimeAll:false, //显示时间弹框
			workStartTime_1:'',
			workEndTime_1:'',
			workStartTime_2:'',
			workEndTime_2:'',
			typeTime:'00',
			userWorkId:'',
			repairType:'',
			staffId:'',

			adduserWorkId:'',
			addrepairType:'',


			typeRemove:'0',
			nowClickIndex:'', //删除的是某一个人的位置 -记录位置
			removeID:'',//删除时间段的位置
			popupRemoveConfim:false,//删除确认框
			showErrorMsg:false,
			errormsg:'',
			addTimeIndex:'',
			removeUserWorkId:'', //删除排班编号
			

			searchDate:'',
			timevalue:'',

			addDay:'', //哪一天的日期下面进行添加排班
			checkStartDay:'',//选中的开始日期
			checkEndDay:'',//选中的结束日期

			loading:true,
			host: window.location.protocol+'//'+window.location.host,
			communityId:'',
			msg:'',
			errorPopup:false,
			triggerType:'',
			triggerAddRepairType:'',
			triggerAddRepair:"",
			select_time:'上班时间段',
			bstap:true,//防重复点击
			bstapBtn:true,
			removeBstap:true,
			removeBstapBtn:true,
			removeDay:'',
			localStorageCommunityId:'',

			
			removesubScribeState:'',


			triggerVillage:'',
			triggerVillageValue:'',
			triggerVillageId:'',
			triggerVillageOptions:[
				{value:'',text:'请选择小区'},
			],

			showVillage: false,
			addIndexId:0,
			clickIndex:0,
			multiColumnList:[
				{
					id:0,
					triggerVillageValue:'',
					triggerVillageId:'',
					showRemoveIcon:false
				}
			],

			showRepairTypeValue: false,
			showRepairPeople: false,
			nowPageStaffId:'',//'3021060916380000137194',//'3021042719330000163483',
			nowPageStaffName:'',//当前页面的员工姓名
			//staffId:'',
			communityIds:'',
			checkAddDay:'',
			rangeDate: '',
			rangeShow: false,
			nowToday:'',
			//scrollToDate:'',
			nowCheckDay:'',
			testDay:'',
			requestHeaders:'',
		}
	},
	created() {
		this.nowPageStaffId = this.queryUrlParam("userId");
		if(!this.nowPageStaffId){
			this.nowPageStaffId = '';
		}

		this.nowPageStaffName = this.queryUrlParam("userName");

		this.nowPageStaffName = this.queryUrlParam('userName');

		var localStorageCommunityId=JSON.parse(localStorage.getItem('hc_currentCommunityInfo'))
		if(localStorageCommunityId){
			this.communityId=localStorageCommunityId.communityId?localStorageCommunityId.communityId:this.getUrlParam("communityId");
		}else{
			this.communityId=this.getUrlParam("communityId");
		}
		this.requestHeaders=getRequestHeaders('00',this.communityId);//获取请求头
        // console.log(this.requestHeaders)
		this.queryRepairOptions();
		this.getSign();
		let date = new Date();
		var date1=date.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
		var today =date1.split('/')[0] + '-'+this.addZero(date1.split('/')[1]) + '-' + this.addZero(date1.split('/')[2])// // 2020-01-01
		this.nowToday = date1;
		this.searchDate=today;
	},
	mounted(){
	},
	filters: {
		subStringThree: function (value) {
            if(typeof value=='object' && value.staffName){
				value = value.staffName;
			}
			if (!value  || (typeof value!='string')){
				return ''
			}
			return value.substring(0,3);
		}
	},
	methods: {
		formatter(day) {
            if(day.type != 'start' &&  day.type != 'end' && day.type !='start-end'){
				const year = day.date.getFullYear();
				const month = day.date.getMonth() + 1;
				const date = day.date.getDate();

				const dateFullName = year+'/'+month+'/'+date;
				for (let i = 0; i < this.sign_days.length; i++) {
					// 当前点击的日相同 staffName
					if (dateFullName == this.sign_days[i].day) {
						//console.log('this.sign_days[i].text，',this.sign_days[i].text)
						if(this.sign_days[i].text.length>1){
                            // topInfo text bottomInfo
							day.bottomInfo = this.beautySub(this.sign_days[i].text[0].staffName)+"\r\n"+this.beautySub(this.sign_days[i].text[1].staffName);
							day.className = 'custom__selected-day';
						}else {
							day.bottomInfo = (this.sign_days[i].text[0].staffName).substring(0,3);
						}
						
						//day.type = 'middle';//selected、start、middle、end、disabled

						if((this.nowToday == dateFullName) && (this.nowToday == this.nowCheckDay)){//className
							day.type = 'selected';
							//day.className = 'custom__selected-day-today';
							//day.className = 'custom__selected-day';
						}else {
							//day.type = 'middle';
							day.className = 'custom__selected-day';
						}
						// if(i == (this.sign_days.length-1)){
						// 	day.type = 'single';
						// 	this.testDay = day;
						// 	console.log('lastday',day)
						// }
					}
				}
			}
			return day;
		},

		beautySub(str,len=3){
			if(str.length>=4){
				str = str.substring(0,3);
			}else if(str.length<len){
				for(var i=0;i<(len-str.length);i++){
					str +="　";
				}
			}
			return str;
		},

		// scrollToDate(day){
		// 	return day;
		// },
		formatRangeDate(date) {
			//console.log('date.day',date.day)
			// date.day.text = '测试';
			// date.topInfo = '劳动节';
			//console.log(175,date);
			return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
		},
		onRangeConfirm(date) {
			const [start, end] = date;
			this.rangeShow = false;
			this.rangeDate = `${this.formatRangeDate(start)} - ${this.formatRangeDate(end)}`;

			this.checkStartDay = `${this.formatRangeDate(start)}`;
			this.checkEndDay = `${this.formatRangeDate(end)}`;
				

		},

		// 查询维修类型
		queryRepairOptions(){
			var that=this;
			var url=this.host+'/app/repair.listRepairSettings';
			var params={
				communityId:'',
				row:50,
				page:1
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					if(res.code=='0'){
						if(res.data.length>0){
							var list=res.data;
							that.allRepairTypeOptions=[
								{value:'',text:'请选择维修类型'}
							];
							list.forEach(function(value,index) {
								that.allRepairTypeOptions.push({
									value:value.repairType,
									text:value.repairTypeName
								})	
							});
						}else{
							that.selectTypeValue='';
							that.selectTypeId='';
							that.allRepairTypeOptions=[
								{value:'',text:'请选择维修类型'}
							];
						}
					}else{
						that.errorPopup=true;
						that.msg=res.msg;
						that.selectTypeValue='';
						that.selectTypeId='';
						that.allRepairTypeOptions=[
							{value:'',text:'请选择维修类型'}
						];
					}
				},
				error:function(res){
					that.selectTypeValue='';
					that.selectTypeId='';
					that.allRepairTypeOptions=[
						{value:'',text:'请选择维修类型'}
					];
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时';
				}
			})
		},
        //查询维修人员
		queryRepairpeople(){
			var that=this;
			var url=this.host+'/app/repair.listRepairTypeUsers';
			var params={
				communityId:'',
				row:50,
				page:1,
				repairType:this.selectTypeId,
				staffId:this.nowPageStaffId,
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					if(res.code=='0'){
						if(res.data.length>0){
							var list=res.data;
							that.allRepairPeople=[]
							list.forEach(function(value,index) {
								that.allRepairPeople.push({
									value:value.staffId,
									text:value.staffName
								})
							});
						}else{
							that.repairPeopleStaffValue='';
							that.repairPeopleStaffId='';
							that.allRepairPeople=[
								{value:'',text:'请选择值班维修人员'}
							];
							that.errorPopup=true;
							that.msg=res.msg;
						}
					}else{
						that.allRepairPeople=[
							{value:'',text:'请选择值班维修人员'}
						];
						that.repairPeopleStaffValue='';
						that.repairPeopleStaffId='';
						that.errorPopup=true;
						that.msg=res.msg;
					}
				},
				error:function(res){
					that.allRepairPeople=[
						{value:'',text:'请选择值班维修人员'}
					];
					that.repairPeopleStaffValue='';
					that.repairPeopleStaffId='';
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时';
				}
			})
		},

		// 直接查询小区
		getCommunitys(){
			var that=this;
			var url=this.host+'/callComponent/nav/getCommunitys';
			var params={
				_uid: '123mlkdinkldldijdhuudjdjkkd',
				page: 1,
				row: 100
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					var list=res.communitys;
					if(list.length>0){
						that.triggerVillageOptions=[
							{value:'',text:'请选择小区'}
						]
						list.forEach(function(value,index) {
							that.triggerVillageOptions.push({
								value:value.communityId,
								text:value.name
							})
						});
					}else{
						that.triggerVillageOptions=[
							{value:'',text:'请选择小区'}
						]
						that.triggerVillageValue='';
						that.triggerVillageId='';
					}
					
				},
				error:function(res){
					that.triggerVillageOptions=[
						{value:'',text:'请选择小区'}
					]
					that.triggerVillageValue='';
					that.triggerVillageId='';
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'

				}
			})

		},
		/**
		 * 获取签到日期
		 */
		getSign () {
			let date = new Date();

			let year = date.getFullYear(); //获取当前年份
			let mon = date.getMonth() + 1; //获取当前月份
			let da = date.getDate(); //获取当前日
			if(mon <10){
				mon = '0'+mon;
			}
			if(da < 10){
				da = '0'+da;
			}

			this.startDate = year+'年'+mon+'月'+da+'日';
			this.bindDate = year+'年'+mon+'月'+da+'日';
			this.beginWorkTime = year+'-'+mon+'-'+da
			// 模拟数据
			this.initData(null);
			this.getPersonNum();
		},
		initData (cur) {
			var date;
			if (cur) { // 切换上一月、下一月
				date = new Date(cur);
			} else {
				var now = new Date(); // 此处取本机时间，应改为服务器时间
				var d = new Date(this.formatDate(now.getFullYear(), now.getMonth() + 1, 1));
				d.setDate(35); // 设置天数为35天（32~59都可以，既设置到下一个月的某一天）
				date = new Date(this.formatDate(d.getFullYear(), d.getMonth(), 1));
			}
			this.currentDay = new Date().getDate(); // 今日日期 几号
			this.currentYear = date.getFullYear(); // 当前年份
			this.currentMonth = date.getMonth() + 1; // 当前月份
			this.currentWeek = date.getDay(); // 当前月1号是星期几？ 0表示星期天
			// 当前月最后一天是星期几？ 0表示星期天
			this.nextWeek = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDay();
			var str = this.formatDate(this.currentYear, this.currentMonth, 1); // 2020/01/01
			var nextStr = new Date(date.getFullYear(), date.getMonth() + 1, 0).toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
			this.days = []; // 初始化日期
			// 设置上一个月 需显示 的最后几天  铺满一周
			for (var i = this.currentWeek; i > 0; i--) {
				var d = new Date(str);
				d.setDate(d.getDate() - i);
				var dayobject = {
					day: d,
					text:this.isText(d),
					isSign: this.isVerDate(d),
					isSigned: this.isSigned(d),
					isToday:this.isToday(d),
					isType:this.isType(d)
				}; // 用一个对象包装Date对象  以便为以后预定功能添加属性
				this.days.push(dayobject); // 将日期放入data 中的days数组 供页面渲染使用
			}
			// console.log(this.days)
			// 显示当前月的天数  第二个循环为 j<= 36- this.currentWeek，
			// 因为1号是星期六的时候当前月需显示6行，如2020年8月
			this.num = 0; //第几个月 每遇到1号加1
			for (var j = 0; j <= 36 - this.currentWeek; j++) {
				var d = new Date(str);
				d.setDate(d.getDate() + j);
				var dddd = d.getDate();
				var dayobject = {
					day: d,
					text:this.isText(d),
					isSign: this.isVerDate(d),
					isSigned: this.isSigned(d),
					isToday:this.isToday(d),
					isType:this.isType(d)
				};
				if (dddd == 1) {
					this.num++
				}
				if (this.num == 2) {
					break
				}
				this.days.push(dayobject);
			}
			// console.log('当前月1号是星期' + this.currentWeek)
			// console.log('当前月最后一天是星期' + this.nextWeek)
			// 设置下一个月 需显示 的最前几天铺满一周
			for (var k = 1; k <= 6 - this.nextWeek; k++) {
				var d = new Date(nextStr);
				d.setDate(d.getDate() + k);
				var dayobject = {
					day: d,
					text:this.isText(d),
					isSign: this.isVerDate(d),
					isSigned: this.isSigned(d),
					isToday:this.isToday(d),
					isType:this.isType(d)
				}; // 用一个对象包装Date对象  以便为以后预定功能添加属性
				this.days.push(dayobject); // 将日期放入data 中的days数组 供页面渲染使用
			}
		},
		/**
		 * 判断该日期是否有任务
		 * @param d
		 * @returns {boolean}
		 */
		isVerDate(d) {
			var signdays = [];
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			var t;
			var sinday=[];
			for (var i in this.sign_days) {
				signdays.push(this.sign_days[i].day);
			}
			var t = signdays.indexOf(r) == '-1' ? false : true;
			return t;
			// return signdays.includes(d.toLocaleDateString());//ie不兼容
		},
		/**
		 * 判断该日期是否有任务并且已完成
		 * @param d
		 * @returns {boolean}
		 */
		isSigned (d) {
			var signdays = [];
			for (var i in this.sign_days) {
				if (this.sign_days[i].is_sign) {
					signdays.push(this.sign_days[i].day);
				}
			}	
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			var t = signdays.indexOf(r) == '-1' ? false : true;
		
			return t;
			// return signdays.includes(d.toLocaleDateString());
		},
		isText(d){
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			for (var i in this.sign_days) {
				if (this.sign_days[i].day==r) {
					return this.sign_days[i].text;
				}
			}
		},
		isType(d){
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			for (var i in this.sign_days) {
				if (this.sign_days[i].day==r) {
					return this.sign_days[i].orgName;
				}
			}
		},
		isToday(d){
			var r = d.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			var now=new Date();
			var now_time=now.getFullYear()+'/'+Number(now.getMonth()+1)+'/'+now.getDate();
			if(r==now_time){
				return true;
			}
		},
		/**
		 * 上一月
		 * @param year
		 * @param month
		 */
		pickPre (year, month) {
			var d = new Date(this.formatDate(year, month, 1));
			d.setDate(0);
			this.selectMonth=d.getMonth() + 1
			this.initData(this.formatDate(d.getFullYear(), this.selectMonth, 1));
			// this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1));
		},
		/**
		 * 下一月
		 * @param year
		 * @param month
		 */
		pickNext(year, month) {
			var d = new Date(this.formatDate(year, month, 1));
			d.setDate(35);
			this.selectMonth=d.getMonth() + 1
			this.initData(this.formatDate(d.getFullYear(), this.selectMonth, 1));
			// this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1));
		},
		// 返回 类似 2020/01/01 格式的字符串
		formatDate (year, month, day) {
			month < 10 && (month = '0' + month);
			day < 10 && (day = '0' + day);
			var data = year + '/' + month + '/' + day;

			return data;
		},
		/**
		 * 点击日期查询
		 * @param index
		 */
		dayCheck(day,flag='no') {
			var currentPlan = {
				title: '',
				date: '',
				list: []
			};
			var date1=day.day.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
			currentPlan.date =date1.split('/')[1] + '月' + date1.split('/')[2] +
				'日';
			this.addDay =date1.split('/')[0] + '-'+this.addZero(date1.split('/')[1]) + '-' + this.addZero(date1.split('/')[2])
			for (var i in this.days) {
				if(this.fm(day.day)== this.fm(this.days[i].day)){
					this.$set(this.days[i], 'isChecked', 1);
					if(flag =='yes'){
						if(i>20){
							this.bottomId = 'm_second'
						}else{
							this.bottomId = 'm_first'
						}
						//this.scrollTOview(this.bottomId);
					}
				}else{
					this.$set(this.days[i], 'isChecked', 0)
				}
			}
			this.searchDate=this.addDay;
			this.$set(day, 'isChecked', 1);
			this.currentPlan = currentPlan
			this.loading=true; //加载展示

			this.getTodayPlace(this.fm(day.day));
			// this.choose('0')

			
		},
		//获取两日期之间日期列表函数
		getdiffdate(stime,etime){
			//初始化日期列表，数组
			var diffdate = new Array();
			var i=0;
			// $(".day-range-checked2").removeClass('day-range-checked2');
			//开始日期小于等于结束日期,并循环
			while(stime<etime){
				diffdate[i] = stime;

				//获取开始日期时间戳
				var stime_ts = new Date(stime).getTime();
				//console.log('当前日期：'+stime   +'当前时间戳：'+stime_ts);

				//增加一天时间戳后的日期
				var next_date = stime_ts + (24*60*60*1000);
				$("#day_"+next_date).addClass('day-range-checked2');

				//拼接年月日，这里的月份会返回（0-11），所以要+1
				var next_dates_y = new Date(next_date).getFullYear()+'/';
				var next_dates_m = (new Date(next_date).getMonth()+1 < 10)?'0'+(new Date(next_date).getMonth()+1)+'/':(new Date(next_date).getMonth()+1)+'/';
				var next_dates_d = (new Date(next_date).getDate() < 10)?'0'+new Date(next_date).getDate():new Date(next_date).getDate();

				stime = next_dates_y+next_dates_m+next_dates_d;

				//console.log('stime',stime);
				//增加数组key this.$set(hisCheckEndDay, 'isRangeChecked', 0);
				i++;
			}
			//console.log(diffdate);
		},

		changeDateType(day,type=1){
			let date1 = day.day.toLocaleDateString().replace(/(年|月)/g, '-').replace('日', '-').replace(/[^\d-/]/g,'-');
			if(type == 1){
				return date1.split('/')[0] + '/'+this.addZero(date1.split('/')[1]) + '/' + this.addZero(date1.split('/')[2]);
			}
			return   date1.split('/')[0] + '-'+this.addZero(date1.split('/')[1]) + '-' + this.addZero(date1.split('/')[2]);
		},

		addZero(n){
		 	return	n=n<10?'0'+n:n;
		},
		removeZero(n){
			return n<10?Number(n):n
	   },
		selectMonthChange(e){
			// console.log(e)
			// console.log(e.target.selectedIndex) // 选择项的index索引
			// console.log(e.target.value) // 选择项的value
			this.selectMonth=e.target.value;
			var D=new Date();
			var year=D.getFullYear()
			var d = new Date(this.formatDate(year, this.selectMonth, 1));
			d.setDate(0);
			this.initData(this.formatDate(d.getFullYear(), this.selectMonth, 1));
		},

		clickNowDay(){
			this.getSign();
		},
		/*查询最近15天排班*/
		getPersonNum(clickDay){
			var that=this;
			var today=new Date().toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			today =today.split('/')[0] + '-'+this.addZero(today.split('/')[1]) + '-' + this.addZero(today.split('/')[2])
			var url=this.host+'/app/repair.listStaffSubscribe';
			// var url=this.host+'/app/repair.listRecentlyDaysRepairSchedulingList';
			var params={
				// communityId:'',
				// repairType:that.querySelectTypeId,
				// beginWorkTime:'',
				// days:''
				staffId:this.nowPageStaffId,
				beginTime:today,
				endTime:'',
				days:90
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					// console.log(res);
					if(res.code=='200'){
						setTimeout(function(){
							that.loading=false;
						},800)
						if(res.data.length>0){
							var list=res.data;
							//console.log('15天排班接口',list)
							var listArr=[];
							list.forEach(function(item, index) {
								var day = item.formatterDate.replace('-','/');
								day = day.replace('-','/');	
								listArr.push({
									day: day,
									is_sign: 2,
									text:item.data,
									orgName:item.orgName
								})
							})
							that.sign_days = listArr;
							that.$refs.calendarDate.scrollToDate(new Date(today))
							if(clickDay){ //新增排班成功后 定位到当前增加排班日期位置
								var d=new Date(clickDay);
								var year=d.getFullYear();
								var month=d.getMonth()+1;
								var days=d.getDate();
								var day = {
									day:  new Date(that.formatDate(year,month, days)),
									text:that.isText(d),
									isSign: that.isVerDate(d),
									isSigned: that.isSigned(d),
									isToday:that.isToday(d)
								};
								d.setDate(0);
								that.initData(that.formatDate(year, month, 1));
								that.dayCheck(day,'yes');
							}else{
								that.initData(null);
								that.initStart();
							}
					
						}else{//无数据的展示
							var listArr=[];
							listArr.push({
								day: '',
								is_sign: 2,
								text:'',
								orgName:''
							})
							that.sign_days = listArr;
							that.initData(null);
							that.initStart();
						}
					}else{
						that.loading=false;
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.loading=false;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		initStart() {
			// console.log(1006,this.beginWorkTime)
			var d=new Date(this.beginWorkTime);
			var year=d.getFullYear();
			var month=d.getMonth()+1;
			var days=d.getDate();
			// console.log(year)
			// console.log(month)
			// console.log(days)
			var day = {
				day:  new Date(this.formatDate(year,month, days)),
				text:this.isText(d),
				isSign: this.isVerDate(d),
				isSigned: this.isSigned(d),
				isToday:this.isToday(d)
			};
			d.setDate(0);
			this.initData(this.formatDate(year, month, 1));
			this.dayCheck(day,'yes');
		},
		fm(date){
			var date1=date.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
			return date1
		},
		scrollTOview(id){
			setTimeout(function(){
				$('#clickId').attr('href','#'+id).click();
				document.getElementById(id).scrollIntoView()
			},100)
		},
		/*查询某天排班*/
		getTodayPlace(date){
			// console.log('getTodayPlace==date==',date)
			let checkType = 1;
			//console.log('getTodayPlace',date)
			if(typeof date=='object' && date[1]){
				date = date[1];
			}else if(typeof date=='object' && date[0]){
				date = date[0];
				checkType=2;
			}else {
				checkType=2;
			}
			// if(date[0]){
			// 	date[0].type = 'selected';
			// }
			var that = this;
			that.personList = [];
			// console.log(date)
			var d=new Date(date);
			var year=d.getFullYear();
			var month=d.getMonth()+1;
			var days=d.getDate();
			if(checkType == 2){
				this.checkStartDay = year+'-'+ month+'-'+days;
				this.checkEndDay = '';
			}
			this.nowCheckDay = year+'/'+ month+'/'+days;
			if(month <10){
				month = '0'+month;
			}
			if(days <10){
				days = '0'+days;
			}
			var daytime = year+'-'+ month+'-'+days;

			this.addDay = daytime;


			// let url=this.host+'/app/repair.listDayRepairSchedulingListByManager';
			var url=this.host+'/app/repair.listStaffSubscribe';
			var params={
				// communityId:'',
				// workTime:daytime,
				// repairType:that.querySelectTypeId,
				staffId:this.nowPageStaffId,//'3021042719330000163483',//
				beginTime:daytime,
				endTime:'',
				days:''
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询某天排班接口',res);
					if(res.code=='200'){
						that.loading=false;
						if(res.data.length>0){
							var list=res.data[0].data;
							that.personList = list;
						}else{

						}
					}else{
						that.loading=false;
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.loading=false;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		choose(index,item) {
			// console.log(index)
			this.chooseNum = this.chooseNum +1;
			var n = this.chooseNum % 2;
			if(n == 1){
				this.chooseFlag = true
			}else{
				this.chooseFlag = false
			};
			if(this.isShow == index){
				this.isShow = '-1';
				return;
			}
			this.isShow = index
			this.staffId = item.staffId;
		},
		//添加排班弹框
		addSchedul(){
			var that=this;
			this.getCommunitys();//查询小区
			that.select_time='上班时间段';
			that.timevalue='';
			that.workStartTime_2='';
			that.workEndTime_2='';

			that.selectTypeId='';
			that.selectTypeValue='';
			that.repairPeopleStaffValue='';
			that.repairPeopleStaffId='';

			that.allRepairPeople=[
				{value:'',text:'请选择值班维修人员'}
			];
			
			that.triggerVillageOptions=[
				{value:'',text:'请选择小区'}
			];
			that.triggerVillageValue='';
			that.triggerCommunityId='';
			that.showSchedulAll=true;

			// if(this.checkStartDay){
			// 	that.checkAddDay = this.changeDateType(this.checkStartDay,2);
			// }
			setTimeout(function(){
				that.showSchedul=true;
			},50)

		},
		//关闭添加排班弹框
		closePopup(){
			var that=this;
			this.showSchedul=false;
			setTimeout(function(){
				that.showSchedulAll=false;
			},350)
		},
		//上班时间段选择弹框
		timeSelect(type,index,staffId,communityInfo){
			this.typeTime=type;//00添加时间段   01新增排班-添加时间段 
			if(this.typeTime=='00'){
				this.addTimeIndex=index; //获取哪一个的添加时间段
				// this.userWorkId=userWorkId; //排班编号
				// this.repairType=repairType;//维修类型
			}
			this.showTime=true;
			this.showTimeAll=true;
			this.staffId = staffId;
			var listArr = [];
			if(communityInfo){
				communityInfo.forEach(function(item, index) {
					listArr.push(
						item.communityId
					)
				})
			}

			this.communityIds = listArr;

		},
		//关闭上班时间段弹框
		cancalTime(){
			var that=this;
			this.showTime=false;
			setTimeout(function(){
				that.showTimeAll=false;
			},400)
		},
		//确认 上班时间段弹框
		confimTime(){
			var that=this;
			if(this.typeTime=='00'){
				if(!this.workStartTime_1){
					this.showErrorMsg=true;
					this.errormsg='上班开始时间不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)	
					return;
				}
				if(!this.workEndTime_1){
					this.showErrorMsg=true;
					this.errormsg='下班结束时间不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return;
				}
				if(this.timeComparison(this.workStartTime_1,this.workEndTime_1)){
					this.showErrorMsg=true;
					this.errormsg='上班开始时间不能大于或等于下班结束时间';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return;
				}
				if(this.bstap==false){
					return
				}
				//添加时间端段接口
				let url=this.host+'/app/repair.addRepairWorkTimeByManager';
				let params={
					"communityId":this.communityId,
					"workTime":this.addDay,
					// "repairType":this.repairType,
					// "userWorkId":this.userWorkId,
					"beginTime":this.addDay+' '+this.workStartTime_1+':00',
					"endTime":this.addDay+' '+this.workEndTime_1+':00',
					"staffId":this.staffId,
					"communityIds":this.communityIds,
				}
				this.bstap=false;
				$.ajax({
					url : url,
					type: 'POST',
					dataType:'json',
					contentType: 'text/plain',
					headers:that.requestHeaders,
					data: JSON.stringify(params),
					success : function (res){
						that.bstap=true;
						if(res.code=='200'){
							that.personList[that.addTimeIndex].subscribe.push({
								"communityId":that.communityId,
								"workTime":that.addDay,
								"beginTime":that.workStartTime_1,
								"endTime":that.workEndTime_1,
								"staffId":that.staffId
							})
						
							that.showErrorMsg=true;
							that.workStartTime_1='';
							that.workEndTime_1='';
							that.errormsg='新增成功！';
							var day =that.addDay.split('-')[0] + '/'+that.removeZero(that.addDay.split('-')[1]) + '/' + that.removeZero(that.addDay.split('-')[2])
							that.getTodayPlace(day);
							setTimeout(function(){
								that.showErrorMsg=false;
							},1000)
							that.showTime=false;
							setTimeout(function(){
								that.showTimeAll=false;
							},400);
						}else{
							console.log(res)
							that.errorPopup=true;
							that.msg=res.msg
						}
					},
					error:function(res){
						that.bstap=true;
						console.log(res)
						that.errorPopup=true;
						that.msg=res.responseText?res.responseText:'请求超时'
					}
				})
			}else{
				if(!this.workStartTime_2){
					this.showErrorMsg=true;
					this.errormsg='上班开始时间不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)	
					return;
				}
				if(!this.workEndTime_2){
					this.showErrorMsg=true;
					this.errormsg='下班结束时间不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return;
				}
				if(this.timeComparison(this.workStartTime_2,this.workEndTime_2)){
					this.showErrorMsg=true;
					this.errormsg='上班开始时间不能大于或等于下班结束时间';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return;
				}
				this.showTime=false;
				this.select_time=this.workStartTime_2+"~"+this.workEndTime_2
				setTimeout(function(){
					that.showTimeAll=false;
				},400);
				// console.log(this.workStartTime_2,this.workEndTime_2)
			}
		},
		showRemoveConfim(type,index,indexId,userSubscribeId){
			// console.log(type,index,indexId,userSubscribeId)
			//index 第几个人下面的排班详情位置
			//indexId 删除的是哪一个排班时间段位置
			this.popupRemoveConfim=true;
			this.typeRemove=type;
			if(type=='01'){			
				// console.log(index,indexId)
				this.nowClickIndex=index;
				this.removeID=indexId;
				this.removesubScribeState=userSubscribeId;
			}else{
				this.removeUserWorkId=index;
				this.removeDay=indexId;
			}
		},
		//确认删除
		removeConfim(){
			let that=this;
			if(this.typeRemove=='00'){//调删除接口
				let url=this.host+'/app/repair.deleteRepairSchedulingByManager';
				let params={
					"date":this.addDay,
					"staffId":this.staffId,
					"communityId":this.communityId,
					"userWorkId":this.removeUserWorkId,
				}

				if(that.removeBstap==false){
					return;
				}
				that.removeBstap=false
				$.ajax({
					url : url,
					type: 'POST',
					dataType:'json',
					contentType: 'text/plain',
					headers:that.requestHeaders,
					data: JSON.stringify(params),
					success : function (res){
						that.removeBstap=true
						if(res.code=='200'){
							that.showErrorMsg=true;
							that.errormsg='删除成功！';
							setTimeout(function(){
								that.showErrorMsg=false;
							},1500)
							that.popupRemoveConfim=false;

							var day =that.addDay.split('-')[0] + '/'+that.removeZero(that.addDay.split('-')[1]) + '/' + that.removeZero(that.addDay.split('-')[2])
							// console.log('删除前that.addDay=',that.addDay)
							// console.log('删除前day=',day)
							// that.getTodayPlace(day);
							that.getPersonNum(day);
							return;	
						}else{
							that.errorPopup=true;
							that.msg=res.msg
						}
					},
					error:function(res){
						that.removeBstap=true
						that.errorPopup=true;
						that.msg=res.responseText?res.responseText:'请求超时'
					}
				})
			}else{//时间段删除-接口调用
				let url=this.host+'/app/repair.deleteRepairWorkTimeByManager';
				let params={
					"communityId":this.communityId,
					"userSubscribeId":this.removesubScribeState,
				}
				if(that.removeBstapBtn==false){
					return;
				}
				that.removeBstapBtn=false;
				$.ajax({
					url : url,
					type: 'POST',
					dataType:'json',
					contentType: 'text/plain',
					headers:that.requestHeaders,
					data: JSON.stringify(params),
					success : function (res){
						that.removeBstapBtn=true;
						if(res.code=='200'){
							that.showErrorMsg=true;
							that.errormsg='删除成功！';
							that.personList[that.nowClickIndex].subscribe.splice(that.removeID,1);
							that.popupRemoveConfim=false;
							setTimeout(function(){
								that.showErrorMsg=false;
							},1500)
					
							return;	
						}else{
							that.popupRemoveConfim=false;
							that.errorPopup=true;
							that.msg=res.msg
						}
					},
					error:function(res){
						that.removeBstapBtn=true;
						that.popupRemoveConfim=false;
						that.errorPopup=true;
						that.msg=res.responseText?res.responseText:'请求超时'
					}
				})
				
			}
		},
		//保存按钮 --排班时间保存
		submitSave(){},
		//小区去重
		communityIdRepeat(arr){
			return arr.filter(function(item, index, arr) {
				//当前元素，在原始数组中的第一个索引==当前索引值，否则返回当前元素
				return arr.indexOf(item, 0) === index;
			});
		},
		//新增排班提交接口
		submit_add(){
			let that=this;
			var communityIdArray=[];
			var staffIdArray=that.repairPeopleStaffId.split();
			for(var i=0;i<this.multiColumnList.length;i++){
				if(that.multiColumnList[i].triggerVillageId){
					communityIdArray.push(that.multiColumnList[i].triggerVillageId)
				}
			}
			if(that.bstapBtn==false){
				return;
			}
			// let url=that.host+'/app/repair.addRepairSchedulingByManager';
			let url=that.host+'/app/repair.addStaffSubscribe'; 
			if(communityIdArray.length<=0){
				that.showErrorMsg=true;
				that.errormsg='小区不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}

			else if(that.select_time=='上班时间段' || that.select_time =='' ){
				that.showErrorMsg=true;
				that.errormsg='上班时间段不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}else if(that.timevalue==''){
				that.showErrorMsg=true;
				that.errormsg='时间间隔不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}

			if(!this.nowPageStaffId){
				if(that.selectTypeId==''){
					that.showErrorMsg=true;
					that.errormsg='维修类型不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return
				}else if(that.repairPeopleStaffId==''){
					that.showErrorMsg=true;
					that.errormsg='维修人员不能为空';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return
				}
			}
		   
			let params={
				"communityId":that.communityId,
				"repairType":that.selectTypeId,
				"workTime":that.addDay,
				"staffIdArray":this.nowPageStaffId?[this.nowPageStaffId]:staffIdArray,
				"beginTime":that.workStartTime_2,
				"endTime":that.workEndTime_2,
				"paragraphTime":that.timevalue,
				//"beginDate":that.addDay,
				"communityIdArray":that.communityIdRepeat(communityIdArray),
				"beginDate":that.checkStartDay?that.checkStartDay:that.addDay,
				"endDate":that.checkEndDay?that.checkEndDay:''
			}
			that.bstapBtn=false;
			$.ajax({
				url : url,
				type: 'POST',
				dataType:'json',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					console.log('排班提交接口',res);
					that.bstapBtn=true;
					if(res.code=='200'){
						that.showErrorMsg=true;
						that.errormsg='新增成功！';
                        // console.log(that.selectTypeId,that.selectTypeValue)
						that.getPersonNum(that.addDay);
						that.repairPeopleStaffValue='';
						that.repairPeopleStaffId='';
						that.selectTypeValue='';
						that.selectTypeId='';
						// console.log(day)

						that.multiColumnList = [{id:0, triggerVillageValue:'', triggerVillageId:'', showRemoveIcon:false}];

						setTimeout(function(){
							that.showErrorMsg=false;
						},1500)
						that.showSchedul=false;
						setTimeout(function(){
							that.showSchedulAll=false;
						},350)
						return;	
					}else{
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.bstapBtn=true;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		changeDateValue(){
			var d=new Date(this.searchDate);
			var year=d.getFullYear();
			var month=d.getMonth()+1;
			var days=d.getDate();
			var day = {
				day:  new Date(this.formatDate(year,month, days)),
				text:this.isText(d),
				isSign: this.isVerDate(d),
				isSigned: this.isSigned(d),
				isToday:this.isToday(d)
			};
			d.setDate(0);
			this.initData(this.formatDate(year, month, 1));
			this.dayCheck(day,'yes');
		},
		timeBlur(){
			var that=this;	
			if(this.timevalue>0 && this.timevalue<1440){
				this.timevalue=this.getInteger(this.timevalue)
			}else{
				this.showErrorMsg=true;
				this.errormsg='时间间隔为整数且不可超过1440(分钟)';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				this.timevalue='';
				return;
			}

		},
		//获取小数点前面的数字
		getInteger(num){
			var val=num.toString();
			if(val.indexOf('.')==-1){
				return val;
			}else{
				return val.substring(0,val.indexOf('.'))
			}
		},
		//时分比较
		timeComparison(start,end){
			//分割开始时间的时
			let kaiShi = start.split(":")[0];
			//分割开始时间的分
			let kaiFen = start.split(":")[1];
			//分割结束时间的时
			let jieShi = end.split(":")[0];
			//分割结束时间的分
			let jieFen = end.split(":")[1];
			//判断两者的时
			if(kaiShi < jieShi){
				return false;
			}else if(kaiShi == jieShi){
				//如果等于的话就判断两者的分
				if(kaiFen < jieFen){
					return false;
				}else{
					return true;
				}
			}else{
				return true;
			}
		},
		getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if (r != null) return unescape(r[2]);
			return null; //返回参数值
	  
		},
		queryUrlParam(name) {
			var reg = new RegExp("(^|\&\?)" + name + "=([^&]*)(&|$)", "i");
			var r = decodeURI(window.location.href.substr(1)).match(reg);
			if (r != null) {
				return unescape(r[2]);
			} else {
				return null;
			}

		},
	  
		
		//显示选择小区
		clickShow(index){
			this.showVillage=true;
			this.clickIndex=index; //点击添加后的第几个
		},
		//新增小区
		addCommunity(){
			this.addIndexId++
			this.multiColumnList.push({
				id:this.addIndexId,
				triggerVillageValue:'',
				triggerVillageId:'',
				showRemoveIcon:true
			})
		},
		//删除小区
		removeCommunity(item){
			var listLength=this.multiColumnList.length;
			var that=this;
			for(let i=0;i<listLength;i++){
				if(that.multiColumnList[i]==item){
					that.multiColumnList.splice(i,1)
				}
			}	
		},
		//小区确定按钮
		onConfirm(value, index) {
			this.multiColumnList[this.clickIndex].triggerVillageValue=value.text;
			this.multiColumnList[this.clickIndex].triggerVillageId=value.value;
			this.showVillage=false;
		},

		//显示维修类型
		clickShowRepairType(index){
			this.showRepairTypeValue=true;
		},
		//维修类型确定按钮
		onConfirmRepairType(value, index) {
			this.selectTypeValue=value.text;
			this.selectTypeId=value.value;
			this.showRepairTypeValue=false;
			this.queryRepairpeople(this.selectTypeId);
		},

		//显示维修人员
		clickShowRepairPeople(index){
			var that=this;
			if(this.selectTypeId){
				this.showRepairPeople=true;
			}else{
				//添加值班人员先判断维修类型是否已选
				this.showErrorMsg=true;
				this.errormsg='请先选择维修类型';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return;
			}
			
		},
		//维修人员确定按钮
		onConfirmRepairPeople(value, index) {
			this.repairPeopleStaffValue=value.text;
			this.repairPeopleStaffId=value.value;
			this.showRepairPeople=false;
		},
	}
});